import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'state.dart';

class SearchLogic extends GetxController {
  final SearchState state = SearchState();

  @override
  void dispose() {
    state.dispose();
    super.dispose();
  }

  void cancelFocus() {
    FocusManager.instance.primaryFocus?.unfocus();
  }

  void search() {
    state.searchText.value = state.searchController.text;
  }

  void onSearch() {
    search();
    cancelFocus();
  }

  void onFocus() {
    state.focusNode.requestFocus();
  }

  void onCancelButton() {
    state.searchController.text = '';
    search();
    cancelFocus();
  }
}
